package ch.christianschweizer.apps.ereservation.ejb;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public abstract class AbstractService {

	@PersistenceContext
	EntityManager em;

	protected <T> T persist(T entity) {
		em.persist(entity);
		em.flush();
		em.refresh(entity);
		return entity;
	}

	protected <T> T merge(T entity) {
		return em.merge(entity);
	}

	protected <T> T findById(Class<T> type, Long id) {
		return em.find(type, id);
	}

}
